<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    let data1 = {
        name: 'jack',
        age: 18
    }
    console.log('before:', data1)
    Object.defineProperty(data1, 'age', {
        set: function (newAge) {
            console.log(this.name + '现在' + newAge + '岁')
        },
        get: function () {
            return 18;
        }
    })
    //赋值
    data1.age = 18;
    data1.age = 19;
    console.log(data1.age)

    console.log('after:', data1)

</script>
</body>
</html>